package com.tmeone.erpone.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tmeone.erpone.entity.JsonResult;
import com.tmeone.erpone.entity.Order;
import com.tmeone.erpone.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class OrderController  {

    @Autowired
    private OrderService orderService;

    @GetMapping("/orders/{current}/{pageSize}")
    public JsonResult getOrders(@PathVariable(value = "current",required = false)Integer current,@PathVariable(value = "pageSize",required = false)Integer pageSize){
        Page<Order> orderPage = new Page<>(current,pageSize);
        IPage<Order> orderIPage = orderService.OrderPage(orderPage);
        return new JsonResult(1,orderIPage);
    }

    @GetMapping("/orders/{current}/{pageSize}/{orderId}")
    public JsonResult getOrdersByOrderId(@PathVariable(value = "current",required = false)Integer current,@PathVariable(value = "pageSize",required = false)Integer pageSize,@PathVariable("orderId")String orderId){
        Page<Order> orderPage = new Page<>(current,pageSize);
        IPage<Order> orders = orderService.selectOrderByOrderId(orderPage,orderId);
        return new JsonResult(1,orders);
    }
}
